var ws;
var game={
    room:0,
    room_number:globalData.roomNumber,
    status:0,
    time:-1,
    round:0,
    total_num:12,
    cardDeal:0,
    can_open:0,
    current_win:0,
    is_play:!1,
    show_card:!1,
    show_coin:!1,
    base_score:0,
    show_score:!1,
    show_bettext:!1,
    poolScore:0,
    pollCoinNum:0,
    chips:[],
    creator_id:0,
};
var message=[
    {num:0,text:"玩游戏，请先进群"},
    {num:1,text:"群内游戏，切勿转发"},
    {num:2,text:"别磨蹭，快点打牌"},
    {num:3,text:"我出去叫人"},
    {num:4,text:"你的牌好靓哇"},
    {num:5,text:"我当年横扫澳门五条街"},
    {num:6,text:"算你牛逼"},
    {num:7,text:"别跟我抢庄"},
    {num:8,text:"输得裤衩都没了"},
    {num:9,text:"我给你们送温暖了"},
    {num:10,text:"谢谢老板"}
];
var wsOperation={
    JoinRoom:"JoinRoom",
    ReadyStart:"ReadyStart",
    CloseRoom:"CloseRoom",
    PrepareJoinRoom:"PrepareJoinRoom",
    AllGamerInfo:"AllGamerInfo",
    UpdateGamerInfo:"UpdateGamerInfo",
    UpdateAccountStatus:"UpdateAccountStatus",
    StartLimitTime:"StartLimitTime",
    CancelStartLimitTime:"CancelStartLimitTime",
    GameStart:"GameStart",
    CardInfo:"CardInfo",
    UpdateAccountScore:"UpdateAccountScore",
    Win:"Win",
    BroadcastVoice:"BroadcastVoice",
    PlayerMultiples:"PlayerMultiples",
    ShowCard:"ShowCard",
    UpdateAccountShow:"UpdateAccountShow",
    UpdateAccountMultiples:"UpdateAccountMultiples",
    StartBet:"StartBet",
    StartShow:"StartShow",
    RefreshRoom:"PullRoomInfo",
    MyCards:"MyCards",
    GameOver:"GameOver",
};
var httpModule={
    getManageInfo: function() {
        var postData = { "account_id": userData.accountId, "room_number": globalData.roomNumber, "game_type":globalData.gameType };
        Vue.http.post(globalData.baseUrl + 'f/getManageInfo', postData).then(function(response) {
            logMessage(response.body);
            var bodyData = response.body;

            if (bodyData.result == 0) {
                if (bodyData.data.length == 0) {
                    if (appData.roomCard <= 0) {
                        reconnectSocket();
                        appData.is_connect = true;
                    } else {
                        reconnectSocket();
                        appData.is_connect = true;
                    }
                } else {
                    appData.activity = bodyData.data.concat();
                    viewMethods.clickShowAlert(5, appData.activity[0].content);
                }
            } else {
                viewMethods.clickShowAlert(8, bodyData.result_message);
                //alert(bodyData.result_message);
            }

        }, function(response) {
            logMessage(response.body);
        });
    }
};
var socketModule={
    closeSocket:function(){
        if(ws)
            try{
                ws.close()
            }catch(e){
                console.log(e)
            }
    },
    sendData:function(e){
        try{
            console.log("websocket state："+ws.readyState);
            if(ws.readyState==WebSocket.CLOSED)
                return void reconnectSocket();
            if(ws.readyState==WebSocket.OPEN){
                ws.send(JSON.stringify(e));
            } else if(ws.readyState==WebSocket.CONNECTING){
                setTimeout(function(){
                    socketModule.sendData(e);
                },1e3);
            } else {
                console.log("websocket state："+ws.readyState);
            }
        }catch(e){
            console.log(e)
        }
    },
    sendPrepareJoinRoom:function(){
        socketModule.sendData({
            operation:wsOperation.PrepareJoinRoom,
            account_id:userData.accountId,
            session:globalData.session,
            data:{
                room_number:globalData.roomNumber
            }
        });
    },
    sendJoinRoom:function(){
        socketModule.sendData({
            operation:wsOperation.JoinRoom,
            account_id:userData.accountId,
            session:globalData.session,
            data:{
                room_number:globalData.roomNumber
            }
        });
    },
    sendRefreshRoom:function(){
        socketModule.sendData({
            operation:wsOperation.RefreshRoom,
            account_id:userData.accountId,
            session:globalData.session,
            data:{
                room_id:appData.game.room
            }
        });
    },
    sendReadyStart:function(){
        socketModule.sendData({
            operation:wsOperation.ReadyStart,
            account_id:userData.accountId,
            session:globalData.session,
            data:{
                room_id:appData.game.room
            }
        });
    },
    sendCloseRoom:function(){
        socketModule.sendData({
            operation:wsOperation.CloseRoom,
            account_id:userData.accountId,
            session:globalData.session,
            data:{
                room_number:globalData.roomNumber
            }
        });
    },
    sendBroadcastVoice:function(e){
        socketModule.sendData({
            operation:wsOperation.BroadcastVoice,
            account_id:userData.accountId,
            session:globalData.session,
            data:{
                room_id:appData.game.room,
                voice_num:e
            }
        });
    },
    sendPlayerMultiples:function(e){
        console.log("atet:"+e);
        socketModule.sendData({
            operation:wsOperation.PlayerMultiples,
            account_id:userData.accountId,
            session:globalData.session,
            data:{
                room_id:appData.game.room,
                multiples:e
            }
        });
    },
    sendShowCard:function(){
        socketModule.sendData({
            operation:wsOperation.ShowCard,
            account_id:userData.accountId,
            session:globalData.session,
            data:{
                room_id:appData.game.room
            }
        });
    },
    processGameRule:function(e){
        if(e.data.ticket_type){
            appData.ruleInfo.ticket=e.data.ticket_type;
            appData.ruleInfo.baseScore=e.data.score_type;
            appData.ruleInfo.timesType=e.data.rule_type;
            appData.ruleInfo.is_cardjoker=Math.ceil(e.data.is_cardjoker);
            appData.ruleInfo.is_cardbao9=Math.ceil(e.data.is_cardbao9);
            appData.ruleInfo.banker_mode=Math.ceil(e.data.banker_mode);
            appData.ruleInfo.banker_score=Math.ceil(e.data.banker_score_type);
        }
       
        1==appData.ruleInfo.banker_mode?
        appData.ruleInfo.bankerText="抢庄":
        2==appData.ruleInfo.banker_mode?
        appData.ruleInfo.bankerText="抢庄":
        3==appData.ruleInfo.banker_mode?
        appData.ruleInfo.bankerText="选庄":
        4==appData.ruleInfo.banker_mode?
        appData.ruleInfo.bankerText="":
        5==appData.ruleInfo.banker_mode&&(appData.ruleInfo.bankerText="")
    },
    processPrepareJoinRoom:function(e){
        if(4==e.data.room_status) {
            appData.roomStatus=e.data.room_status;
            viewMethods.clickShowAlert(2,e.result_message);
            return;
        }
        if(e.data.ticket_type){
            appData.ruleInfo.ticket=e.data.ticket_type;
            appData.ruleInfo.baseScore=e.data.score_type;
            appData.ruleInfo.timesType=e.data.rule_type;
            appData.ruleInfo.is_cardjoker=Math.ceil(e.data.is_cardjoker);
            appData.ruleInfo.is_cardbao9=Math.ceil(e.data.is_cardbao9);
            appData.ruleInfo.banker_mode=Math.ceil(e.data.banker_mode);
            appData.ruleInfo.banker_score=Math.ceil(e.data.banker_score_type);
            appData.ruleInfo.bet_type=Math.ceil(e.data.bet_type);
        }

        if(1==appData.ruleInfo.bet_type){
            appData.game.chips=[30,60,90,120,150,180,210,240,270,300];
        } else if(2==appData.ruleInfo.bet_type){
            appData.game.chips=[50,100,150,200,250,300,350,400,450,500];
        } else if(3==appData.ruleInfo.bet_type){
            appData.game.chips=[100,200,300,400,500,600,700,800,900,1000];
        }

        appData.raiseChip=appData.game.chips[0];
        
        wxModule.config();

        if(3!=e.data.room_status){
            if(0==e.data.user_count){
                socketModule.sendJoinRoom();
            } else if(""!=e.data.alert_text){
                viewMethods.clickShowAlert(4,e.data.alert_text);
            } else {
                socketModule.sendJoinRoom();
            }
        }
    },
    processJoinRoom:function(e){
        appData.game.room=e.data.room_id;
        appData.game.round=Math.ceil(e.data.game_num);
        appData.game.total_num=Math.ceil(e.data.total_num);
        appData.game.base_score=Math.ceil(e.data.base_score);
        appData.game.poolScore=parseInt(e.data.score_pool);
        appData.base_score=appData.game.base_score;
        appData.canBreak=Math.ceil(e.data.can_break);
        appData.game.creator_id = Math.ceil(e.data.creator_id);
        resetAllPlayerData();

        if(-1==e.data.limit_time){
            appData.game.time=Math.ceil(e.data.limit_time);
            viewMethods.timeCountDown();
        }
        appData.player[0].serial_num=e.data.serial_num;
        for(var t=0;t<12;t++){
            if(t<=12-e.data.serial_num){
                appData.player[t].serial_num=t+Math.ceil(e.data.serial_num);
            } else {
                appData.player[t].serial_num=t+Math.ceil(e.data.serial_num)-12; 
            }
        }

        appData.player[0].account_status=Math.ceil(e.data.account_status);
        appData.player[0].account_score=Math.ceil(e.data.account_score);
        appData.player[0].nickname=userData.nickname;
        appData.player[0].headimgurl=userData.avatar;
        appData.player[0].account_id=userData.accountId;
        appData.player[0].account_code=userData.account_code;
        appData.player[0].card=e.data.cards.concat();
        appData.player[0].card_open=e.data.cards.concat();
        appData.player[0].card_type=e.data.card_type;
        appData.player[0].ticket_checked=e.data.ticket_checked;
        appData.game.status=Math.ceil(e.data.room_status);
        appData.player[0].combo_point=e.data.combo_point;
        //appData.player[0].card_open=getComboCards(e.data.cards.concat());

       
        if(2==appData.game.status){
            appData.game.cardDeal = 3;
        }
        
        appData.scoreboard=e.data.scoreboard;
        viewMethods.resetMyAccountStatus();
    },
    processRefreshRoom:function(e){
        resetAllPlayerData();
        appData.player[0].serial_num=e.data.serial_num;
        for(t=0;t<12;t++)
            if(t<=12-e.data.serial_num){
                appData.player[t].serial_num=t+Math.ceil(e.data.serial_num);
            } else {
                appData.player[t].serial_num=t+Math.ceil(e.data.serial_num)-12;
            }
        appData.player[0].account_status=Math.ceil(e.data.account_status);
        appData.player[0].account_score=Math.ceil(e.data.account_score);
        appData.player[0].nickname=userData.nickname;
        appData.player[0].account_code=userData.account_code;
        appData.player[0].headimgurl=userData.avatar;
        appData.player[0].account_id=userData.accountId;
        appData.player[0].serial_num=e.data.serial_num;
        appData.player[0].card=e.data.cards.concat();
        appData.player[0].card_open=e.data.cards.concat();
        appData.player[0].card_type=e.data.card_type;
        appData.player[0].ticket_checked=e.data.ticket_checked;
        appData.player[0].combo_point=e.data.combo_point;
        //appData.player[0].card_open=getComboCards(e.data.cards.concat());
        if(2==appData.game.status){
            appData.game.cardDeal=3;
        }

        for(var t=0;t<12;t++)
            for(var a=0;a<e.all_gamer_info.length;a++)
                if(appData.player[t].serial_num==e.all_gamer_info[a].serial_num){
                    appData.player[t].nickname=e.all_gamer_info[a].nickname;
                    appData.player[t].account_code=e.all_gamer_info[a].account_code;
                    appData.player[t].headimgurl=e.all_gamer_info[a].headimgurl;
                    appData.player[t].account_id=e.all_gamer_info[a].account_id;
                    appData.player[t].account_score=Math.ceil(e.all_gamer_info[a].account_score);
                    appData.player[t].account_status=Math.ceil(e.all_gamer_info[a].account_status);
                    appData.player[t].online_status=Math.ceil(e.all_gamer_info[a].online_status);
                    appData.player[t].ticket_checked=e.all_gamer_info[a].ticket_checked;
                    appData.player[t].multiples=e.all_gamer_info[a].multiples;
                    appData.player[t].bankerMultiples=e.all_gamer_info[a].banker_multiples;
                    appData.player[t].card_type=e.all_gamer_info[a].card_type;
                    appData.player[t].combo_point=e.all_gamer_info[a].combo_point;
                    appData.player[t].is_showbull=!1;
                    if(1==e.all_gamer_info[a].is_banker){
                        appData.player[t].is_banker=!0;
                        appData.bankerAccountId=e.all_gamer_info[a].account_id;
                        appData.bankerPlayer=appData.player[t];
                    } else {
                        appData.player[t].is_banker=!1;
                    }
                    if(appData.player[t].account_status>=8){
                        appData.player[t].is_showCard=!0;
                    }
                    //appData.player[t].card_open=getComboCards(e.all_gamer_info[a].cards.concat());
                    if(appData.player[t].card_open.length<1||void 0==appData.player[t].card_open){
                        appData.player[t].card_open=e.all_gamer_info[a].cards.concat();
                    }
                    if(appData.player[t].card_open.length<1||void 0==appData.player[t].card_open){
                        appData.player[t].card_open=[-1,-1,-1,];
                    }
                }
        if(appData.player[0].account_status>=7){
            appData.player[0].is_showCard=!0;
        }
        if(appData.player[0].account_status>2){
            setTimeout(function(){
                appData.player[0].is_showCard=!0;
            },500);
        }
        if(3==appData.player[0].account_status){
            appData.showClockRobText=!0;
            setTimeout(function(){
                appData.showRob=!0
            },500);
        }
        if(6==appData.player[0].account_status){
            appData.showClockBetText=!0;
            appData.showRob=!1;
            appData.showRobText=!1;
            appData.showNotRobBankerText=!1;
            appData.showShowCardButton=!1;
            appData.showClickShowCard=!1;
            appData.showBankerCoinText=!1;
            appData.showTimesCoin=!0;
        }
        if(6==appData.player[0].account_status){
            appData.isFinishBankerAnimate=!0;
        }
        viewMethods.resetMyAccountStatus();
        viewMethods.updateAllPlayerStatus();
        if(appData.player[0].account_status>2&&appData.player[0].account_status<7&&
            (2==appData.ruleInfo.banker_mode||6==appData.ruleInfo.banker_mode)){
            viewMethods.seeMyCard();
        }
    },
    processStartShow:function(e){
        var t=0;
        if(4==appData.ruleInfo.banker_mode){
            t=1200;
        }
        setTimeout(function(){
            for(var t=0;t<12;t++)
                for(var a=0;a<e.data.length;a++)
                    if(appData.player[t].account_id==e.data[a].account_id){
                        if(0==appData.player[t].multiples&&0!=e.data[a].multiples){
                            viewMethods.throwCoin(appData.player[t].num,1);
                            appData.player[t].account_score=appData.player[t].account_score-parseInt(e.data[a].multiples);
                            appData.game.poolScore=appData.game.poolScore+parseInt(e.data[a].multiples);
                        }
                        appData.player[t].multiples=e.data[a].multiples;
                        appData.player[t].account_status=parseInt(e.data[a].account_status);
                        appData.player[t].online_status=parseInt(e.data[a].online_status);
                        appData.player[t].card=e.data[a].cards.concat();
                        appData.player[t].card_open=e.data[a].cards.concat();
                        appData.player[t].card_type=e.data[a].card_type;
                        appData.player[t].combo_point=e.data[a].combo_point;
                        appData.player[t].limit_time=e.data[a].limit_time;
                        //appData.player[t].card_open=getComboCards(e.data[a].cards.concat());
                    }

            appData.showClockBetText=!1;
            appData.showClockRobText=!1;
            appData.showClockShowCard=!0;
            viewMethods.resetMyAccountStatus();
            viewMethods.updateAllPlayerStatus();
            appData.game.time=Math.ceil(e.limit_time);
            viewMethods.timeCountDown();
        },t)
    },
    processMyCards:function(e){
        if(2==appData.ruleInfo.banker_mode||6==appData.ruleInfo.banker_mode){
            if(appData.player[0].account_id==e.data.account_id){
                appData.player[0].card=e.data.cards.concat();
            }
            viewMethods.seeMyCard();
        }
    },
    processStartBet:function(e){
        setTimeout(function(){
            for(var t=0;t<12;t++)
                for(var a=0;a<e.data.length;a++)
                    if(appData.player[t].account_id==e.data[a].account_id){
                        appData.player[t].account_status=parseInt(e.data[a].account_status);
                        appData.player[t].online_status=parseInt(e.data[a].online_status);
                        appData.player[t].limit_time=parseInt(e.data[a].limit_time);
                        appData.player[t].multiples=0;
                        if(1==e.data[a].is_banker){
                            appData.player[t].is_banker=!0;
                            appData.bankerAccountId=e.data[a].account_id;
                            appData.bankerPlayer=appData.player[t];
                        } else {
                            appData.player[t].is_banker=!1;
                        }
                    }
            appData.bankerArray=e.grab_array.concat();
            appData.showRob=!1;
            appData.showClockBetText=!0;
            appData.showClockRobText=!1;
            appData.showClockShowCard=!1;
            appData.game.time=parseInt(e.limit_time);
            appData.bankerAnimateIndex=0;
            if(appData.game.time>0){
                viewMethods.timeCountDown();
            }
        },1200)
    },
    processAllGamerInfo:function(e){
        appData.game.show_card=!0;
        appData.game.show_coin=!0;
        appData.clickCard3=!1;
        for(a=0;a<12;a++)
            for(var t=0;t<e.data.length;t++)
                if(appData.player[a].serial_num==e.data[t].serial_num){
                    appData.player[a].nickname=e.data[t].nickname;
                    appData.player[a].account_code=e.data[t].account_code;
                    appData.player[a].headimgurl=e.data[t].headimgurl;
                    appData.player[a].account_id=e.data[t].account_id;
                    appData.player[a].account_score=Math.ceil(e.data[t].account_score);
                    appData.player[a].account_status=Math.ceil(e.data[t].account_status);
                    appData.player[a].online_status=Math.ceil(e.data[t].online_status);
                    appData.player[a].ticket_checked=e.data[t].ticket_checked;
                    appData.player[a].multiples=e.data[t].multiples;
                    appData.player[a].bankerMultiples=e.data[t].banker_multiples;
                    appData.player[a].card_type=e.data[t].card_type;
                    appData.player[a].combo_point=e.data[t].combo_point;
                    appData.player[a].is_showbull=!1;

                    appData.player[a].is_banker=!1;
                    if(appData.player[a].account_status>=8){
                        appData.player[a].is_showCard=!0;
                    }
                    appData.player[a].card_open=e.data[t].cards.concat();
                    if(appData.player[a].card_open.length<1||void 0==appData.player[a].card_open){
                        appData.player[a].card_open=[-1,-1,-1];
                    }
                }
        if(appData.player[0].account_status>=7){
            (appData.player[0].is_showCard=!0);
        }
        if(""!=appData.scoreboard){
            for(var a=0;a<12;a++)
                for(s in appData.scoreboard)
                    if(appData.player[a].account_id==s){
                        appData.playerBoard.score[a].num=appData.player[a].num;
                        appData.playerBoard.score[a].account_id=appData.player[a].account_id;
                        appData.playerBoard.score[a].nickname=appData.player[a].nickname;
                        appData.playerBoard.score[a].account_code=appData.player[a].account_code;
                        appData.playerBoard.score[a].account_score=Math.ceil(appData.scoreboard[s]);
                    }
            if(2==appData.game.status){
                appData.playerBoard.round=appData.game.round-1;
            } else {
                appData.playerBoard.round=appData.game.round
            }
        }
        if(appData.player[0].account_status>2){
            setTimeout(function(){
                    appData.player[0].is_showCard=!0;
            },500);
        }
        if(3==appData.player[0].account_status){
            appData.showClockRobText=!0;
            setTimeout(function(){
                appData.showRob=!0
            },500);
        }
        if(6==appData.player[0].account_status){
            appData.showClockBetText=!0;
            appData.showRob=!1;
            appData.showRobText=!1;
            appData.showNotRobBankerText=!1;
            appData.showShowCardButton=!1;
            appData.showClickShowCard=!1;
            appData.showBankerCoinText=!1;
            appData.showTimesCoin=!0;

            appData.isFinishBankerAnimate=!0
        }
        viewMethods.resetMyAccountStatus();
        viewMethods.updateAllPlayerStatus();
        if(appData.player[0].account_status>2&&appData.player[0].account_status<7&&(2==appData.ruleInfo.banker_mode||6==appData.ruleInfo.banker_mode)){
            viewMethods.seeMyCard();
        }
    },
    processUpdateGamerInfo:function(e){
        logMessage(appData.player);
        for(var t=0;t<12;t++) {
            if(appData.player[t].serial_num==e.data.serial_num){
                appData.player[t].nickname=e.data.nickname;
                appData.player[t].account_code=e.data.account_code;
                appData.player[t].headimgurl=e.data.headimgurl;
                appData.player[t].account_id=e.data.account_id;
                appData.player[t].account_score=Math.ceil(e.data.account_score);
                appData.player[t].account_status=Math.ceil(e.data.account_status);
                appData.player[t].online_status=Math.ceil(e.data.online_status);
                appData.player[t].ticket_checked=e.data.ticket_checked;
            }else if(appData.player[t].account_id==e.data.account_id){
                socketModule.sendRefreshRoom();
            }
        }
    },
    processUpdateAccountStatus:function(e){
        for(var t=0;t<12;t++){
            if(appData.player[t].account_id==e.data.account_id){
                if(2==appData.ruleInfo.banker_mode||6==appData.ruleInfo.banker_mode){
                    if(5==e.data.account_status||4==e.data.account_status)
                        appData.player[t].bankerMultiples=e.data.banker_multiples;
                }
                if(appData.player[t].account_status>=8){
                    appData.player[t].online_status=e.data.online_status;
                    return ;
                }
                if(1==e.data.online_status){
                    appData.player[t].account_status=Math.ceil(e.data.account_status);
                } else if(0==e.data.online_status&&0==appData.player[t].account_status){
                    appData.player[t].account_id=0;
                    appData.player[t].playing_status=0;
                    appData.player[t].online_status=0;
                    appData.player[t].nickname="";
                    appData.player[t].account_code="";
                    appData.player[t].headimgurl="";
                    appData.player[t].account_score=0;
                } else if(0==e.data.online_status && appData.player[t].account_status>0){
                    appData.player[t].account_status=Math.ceil(e.data.account_status);
                    appData.player[t].online_status=0;
                } else {
                    logMessage(e);
                }
                if(0!=t){
                    if(4==appData.player[t].account_status){
                        setTimeout(function(){
                            mp3AudioPlay("audioNoBanker");
                        },100);
                    } else if(5==appData.player[t].account_status){
                        setTimeout(function(){
                            mp3AudioPlay("audioRobBanker");
                        },100);
                    }
                }
                break;
            }
        }

        if(3==appData.player[0].account_status){
            viewMethods.showRobBankerText();
        } else if(4==appData.player[0].account_status){
            viewMethods.showNotRobBankerTextFnc();
        }

        if(appData.isFinishBankerAnimate&&appData.isFinishWinAnimate){
            viewMethods.resetMyAccountStatus();
            viewMethods.updateAllPlayerStatus();
        } else {
            setTimeout(function(){
                viewMethods.resetMyAccountStatus();
                viewMethods.updateAllPlayerStatus();
            },3e3);
        }
    },
    processUpdateAccountShow:function(e){
        for(var t=0;t<appData.player.length;t++)
            if(appData.player[t].account_id==e.data.account_id){
                appData.player[t].card_type=e.data.card_type;
                appData.player[t].cards=e.data.cards.concat();
                appData.player[t].card_open=e.data.cards.concat();
                appData.player[t].combo_point=e.data.combo_point;
                appData.player[t].account_status=8;
                //appData.player[t].card_open=getComboCards(e.data.cards.concat());
                if(0==appData.player[t].is_audiobull&&appData.player[t].account_status>=8){
                    var a="";
                    a=(parseInt(appData.player[t].card_type)>4)?("special"+appData.player[t].card_type):("sangong"+appData.player[t].combo_point);

                    setTimeout(function(){
                        mp3AudioPlay(a)
                    },100);
                    appData.player[t].is_audiobull=!0;
                }
                break;
            }
        if(e.data.account_id==appData.player[0].account_id){
            viewMethods.resetMyAccountStatus();
        }
        viewMethods.updateAllPlayerStatus();
    },
    processUpdateAccountMultiples:function(e){
        appData.game.poolScore=appData.game.poolScore+parseInt(e.data.multiples);
        for(var t=0;t<appData.player.length;t++)
            if(appData.player[t].account_id==e.data.account_id){
                appData.player[t].multiples=e.data.multiples;
                if(0==t)return;
                if(appData.player[t].multiples>=1){
                    for(var a=0;a<appData.game.chips.length;a++)
                        if(appData.player[t].multiples==appData.game.chips[a]){
                            viewMethods.throwCoin(appData.player[t].num,a+1);
                        }
                    appData.player[t].account_score=appData.player[t].account_score-e.data.multiples;
                    var n=appData.player[t].multiples;
                    setTimeout(function(){
                        mp3AudioPlay(n)
                    },100)
                }
                break
            }
        viewMethods.resetMyAccountStatus();
        viewMethods.updateAllPlayerStatus()
    },
    processStartLimitTime:function(e){e.data.limit_time>1&&(appData.game.time=Math.ceil(e.data.limit_time),viewMethods.timeCountDown())},
    processCancelStartLimitTime:function(e){appData.game.time=-1},
    processGameStart:function(e){
        $(".cards").removeClass("card-flipped");
        $(".myCards").removeClass("card-flipped");
        $(".memberCoin").stop(!0);
        appData.isFinishWinAnimate=!0;
        appData.isFinishBankerAnimate=!0;
        appData.game.can_open=0;
        appData.game.cardDeal=0;
        appData.game.status=1;
        appData.game.show_card=!0;
        appData.game.time=-1;
        appData.game.is_play=!0;
        appData.game.round=appData.game.round+1;
        appData.game.round=Math.ceil(e.game_num);
        appData.player[0].is_showCard=!1;
        appData.showClockRobText=!1;
        appData.showClockBetText=!1;
        appData.showClockShowCard=!1;
        appData.clickCard3=!1;
        appData.showClickShowCard=!1;
        appData.breakData=null;
        appData.raiseValue=0;
        appData.raiseChip=appData.game.chips[0];
        for(var t=0;t<12;t++){
            appData.player[t].is_operation=!1;
            appData.player[t].is_showCard=!1;
            appData.player[t].is_showbull=!1;
            if(5==appData.ruleInfo.banker_mode&&appData.game.round>1){

            } else {
                if(3==appData.ruleInfo.banker_mode&&appData.game.round>1){

                } else {
                    appData.player[t].is_banker=!1
                }
            }
            appData.player[t].bullImg="";
            if(0==appData.player[t].online_status){
                appData.player[t].account_status=1;
            }
            for(var a=0;a<e.data.length;a++){
                if(appData.player[t].account_id==e.data[a].account_id){
                    appData.player[t].ticket_checked=1;
                    appData.player[t].account_status=Math.ceil(e.data[a].account_status);
                    appData.player[t].playing_status=Math.ceil(e.data[a].playing_status);
                    appData.player[t].online_status=Math.ceil(e.data[a].online_status);
                    appData.player[t].account_score=appData.player[t].account_score;
                    appData.player[t].limit_time=Math.ceil(e.data[a].limit_time);
                }
            }
        }
        appData.game.status=2;
        viewMethods.reDeal();
    },
    processBroadcastVoice:function(e){
        for(var t=0;t<12;t++)
            if(appData.player[t].account_id==e.data.account_id&&0!=t){
                m4aAudioPlay("message"+e.data.voice_num);
                viewMethods.messageSay(t,e.data.voice_num);
            }
    },
    processWin:function(e){
        appData.game.is_play=!1;
        appData.game.current_win=e.data.win_score;
        appData.game.round=Math.ceil(e.data.game_num);
        appData.game.total_num=Math.ceil(e.data.total_num);
        appData.playerBoard.round=Math.ceil(e.data.game_num);
        appData.game.show_score=!1;
        appData.showClockShowCard=!1;
        appData.showShowCardButton=!1;
        appData.showClickShowCard=!1;
        appData.showClockBetText=!1;
        appData.showClockRobText=!1;

        if(3==appData.ruleInfo.banker_mode){
            appData.bankerID=Math.ceil(e.data.banker_id);
            appData.bankerAccountId=appData.bankerID;
            console.log(appData.bankerID);
        }

        if(5==appData.ruleInfo.banker_mode){
            if(appData.player[0].is_banker){
                appData.canBreak=Math.ceil(e.data.can_break);
            }

            if(void 0!=e.data.is_break && null!=e.data.is_break){
                appData.isBreak=Math.ceil(e.data.is_break);
            }
        }
            
        viewMethods.showMemberScore(!1);

        for(var t=0;t<appData.player.length;t++){
            appData.player[t].single_score=0;
            if(appData.player[t].account_status>=7){
                appData.player[t].account_status=8;
            }
            for(var a=0;a<e.data.loser_array.length;a++)
                if(appData.player[t].account_id==e.data.loser_array[a].account_id){
                    appData.player[t].single_score=e.data.loser_array[a].score;
                    break
                }
            for(var n=0;n<e.data.winner_array.length;n++)
                if(appData.player[t].account_id==e.data.winner_array[n].account_id){
                    appData.player[t].single_score=e.data.winner_array[n].score;
                    break
                }
        }

        appData.game.time=-1;
        viewMethods.updateAllPlayerStatus();
        setTimeout(function(){
            console.log("983: resetMyAccountStatus");
            viewMethods.resetMyAccountStatus();
        },200);

        if(appData.player[0].account_status>=8&&0==appData.player[0].is_audiobull){
            var r=appData.player[0].card_type;
            var o=appData.player[0].combo_point;
            setTimeout(function(){
                if (r > 4) {
                      mp3AudioPlay("special"+appData.player[0].card_type);
                } else {
                      mp3AudioPlay("sangong" + o);
                }
            },200);
            appData.player[0].is_audiobull=!0
        }
        setTimeout(function(){
            viewMethods.winAnimate(e)
        },2000)   //3e3
    },
    processBalanceScoreboard:function(e){
        var t=new Date(parseInt(e.time) * 1000);
        var a=t.getFullYear()+"-";
        var n=t.getMonth()+1+"-";
        var r=t.getDate()+" ";
        var o=t.getHours();
        var i=t.getMinutes();
        var c=":";
        if(i<10)
            c+=0;
        var l=a+n+r+o+c+i;
        appData.playerBoard.round=e.game_num;
        appData.playerBoard.record=l;
        appData.playerBoard.score=[];
        var u=e.scoreboard;
        for(s in u){
            var p=0;
            var d=u[s].name;
            if(userData.accountId==u[s].account_id){
                p=1;
            }
            appData.playerBoard.score.push({
                account_id:u[s].account_id,
                nickname:d,
                account_score:Math.ceil(u[s].score),
                num:p,
                account_code:u[s].account_code
            });
        }
    },
    processLastScoreboard:function(e){
        if(void 0!=e){
            console.log(e);
            try{
                var t=new Date(1e3*parseInt(e.time));
                var a=t.getFullYear()+"-";
                var n=t.getMonth()+1+"-";
                var r=t.getDate()+" ";
                var o=t.getHours();
                var i=t.getMinutes();
                var c=":";
                if(i<10){
                    c+=0;
                }
                var l=a+n+r+o+c+i;
                appData.playerBoard.round=e.game_num;
                appData.playerBoard.record=l;
                appData.playerBoard.score=[];
                if(void 0!=e.total_num&&null!=e.total_num&&""!=e.total_num){
                    appData.game.total_num=e.total_num;
                }
                var u=e.scoreboard;
                for(s in u){
                    var p=0;
                    if(userData.accountId==u[s].account_id){
                        p=1;
                    }
                    appData.playerBoard.score.push({
                        account_id:u[s].account_id,
                        nickname:u[s].name,
                        account_score:Math.ceil(u[s].score),
                        num:p,
                        account_code:u[s].account_code
                    });
                }
                chooseBigWinner();
                $(".ranking .rankBack").css("opacity","1");
                $(".roundEndShow").show();
                $(".ranking").show();
                canvas();
                $("#endCreateRoomBtn").show();
            }catch(e){
                console.log(e);
            }
        }
    }
};
var viewMethods={
    clickShowAlert:function(e,t){
        appData.alertType=e,
        appData.alertText=t,
        appData.isShowAlert=!0,
        setTimeout(function(){
            var t=$(".alertText").height(),a=t;
            t<.15*height&&(t=.15*height),
            t>.8*height&&(t=.8*height);
            var n=t+.056*height*2+.022*height+.056*height;
            8==e&&(n=n-.022*height-.056*height);
            var r=t+.034*height*2,o=.022*height+(r-a)/2;
            $(".alert .mainPart").css("height",n+"px"),
            $(".alert .mainPart").css("margin-top","-"+n/2+"px"),
            $(".alert .mainPart .backImg .blackImg").css("height",r+"px"),
            $(".alert .mainPart .alertText").css("top",o+"px")
        },0)
    },
    clickCloseAlert:function(){
        if(22==appData.alertType){
            appData.isShowAlert=!1;
            httpModule.getManageInfo();
        } else {
            appData.isShowAlert=!1;
        }
    },
    clickSitDown:function(){appData.isShowAlert=!1,socketModule.sendJoinRoom()},
    clickReady:function(){socketModule.sendReadyStart(),appData.player[0].is_operation=!0},
    clickCloseRoom:function(){socketModule.sendCloseRoom(),appData.player[0].is_operation=!0},
    reDeal:function(){
        if(!appData.isDealing){
            appData.isDealing=!0;
            m4aAudioPlay("audio1");
            appData.game.cardDeal=1;
            setTimeout(function(){
                appData.game.cardDeal=2;
                setTimeout(function(){
                    appData.game.cardDeal=3;
                    setTimeout(function(){
                        viewMethods.resetMyAccountStatus();
                        appData.player[0].is_showCard=!0;
                        appData.showClockRobText=!0;
                        appData.isDealing=!1;
                    },300);
                },150);
            },150);
        }
    },
    resetMyAccountStatus:function(){
        if(6!=appData.player[0].account_status||appData.isFinishBankerAnimate){
            viewMethods.resetShowButton();
            if(3==appData.player[0].account_status){
                appData.showRob=!0;
            } else if(4==appData.player[0].account_status){
                appData.showNotRobText=!0;
            } else if(5==appData.player[0].account_status){
                appData.showRobText=!0;
            } else if(6==appData.player[0].account_status){
                appData.isFinishBankerAnimate&&(appData.showTimesCoin=!0);
            } else if(7==appData.player[0].account_status){
                appData.player[0].is_showCard=!0;
                if(1==appData.clickCard3){
                    appData.showShowCardButton=!0;
                } else {
                    appData.showClickShowCard=!0;
                }
            } else if(8==appData.player[0].account_status){
                appData.player[0].is_showCard=!0;
            }
        }
    },
    resetShowButton:function(){
        appData.showTimesCoin=!1;
        appData.showRob=!1;
        appData.showShowCardButton=!1;
        appData.showClickShowCard=!1;
        appData.showNotRobText=!1;
        appData.showRobText=!1;
        appData.showBankerCoinText=!1;
    },
    seeMyCard:function(){
        setTimeout(function(){
            $(".myCards .card0").addClass("card-flipped");
            $(".myCards .card1").addClass("card-flipped");
            setTimeout(function(){
                if(1!=appData.clickCard3)
                    if(appData.player[0].account_status>=7)
                        appData.showClickShowCard=!0;
            },500);
        },1e3);
    },
    seeMyCard3:function(){
        if (appData.player[0].account_status >= 7) {
            $(".myCards .card2").addClass("card-flipped");
            appData.clickCard3 = true;
            setTimeout(function() {
                appData.showShowCardButton = true;
                appData.showClickShowCard = false;
            }, 100)
        }
    },
    
    resetCardOver:function(e){
        if(1==e){
            $(".myCards .card00").css("left","35%");
            $(".myCards .card01").css("left","50%");
            $(".myCards .card02").css("left","65%");
        } else if(2==e || 3==e || 4==e || 5==e){
            $(".cardOver .card"+e+"11").css("right","7.5vh");
            $(".cardOver .card"+e+"21").css("right","9.5vh");
            $(".cardOver .card"+e+"31").css("right","11.5vh");
        } else if(6==e){
            $(".cardOver .card611").css("right","5.5vh");
            $(".cardOver .card621").css("right","7.5vh");
            $(".cardOver .card631").css("right","9.5vh");
        } else if(7==e){
            $(".cardOver .card711").css("right","42%");
            $(".cardOver .card721").css("right","46%");
            $(".cardOver .card731").css("right","50%");
        } else if(8==e){
            $(".cardOver .card811").css("left","5.5vh");
            $(".cardOver .card821").css("left","7.5vh");
            $(".cardOver .card831").css("left","9.5vh");
        }  else if(9==e || 10==e || 11==e || 12==e){
            $(".cardOver .card"+e+"11").css("left","7.5vh");
            $(".cardOver .card"+e+"21").css("left","9.5vh");
            $(".cardOver .card"+e+"31").css("left","11.5vh");
        }
    },
    myCardOver:function(){
        if(1!=appData.player[0].is_showbull){
            //viewMethods.resetCardOver(1);
            
            setTimeout(function(){
                $(".myCards .card00").animate({left:"37%"},400);
                $(".myCards .card01").animate({left:"50%"},400);
                $(".myCards .card02").animate({left:"63%"},400);
            },0);
            
            appData.player[0].is_showbull=!0;
        }
    },
    cardOver:function(e){
        if(e>1 && 1!=appData.player[e-1].is_showbull){
            appData.player[e-1].is_showbull=!0;
            //viewMethods.resetCardOver(e);
            setTimeout(function(){
                if(2==e||3==e||4==e||5==e){
                    $(".cardOver .card"+e+"11").animate({right:"8.5vh"},250);
                    $(".cardOver .card"+e+"21").animate({right:"8.5vh"},250);
                    $(".cardOver .card"+e+"31").animate({right:"8.5vh"},250);
                        setTimeout(function(){
                            $(".cardOver .cardtf"+e).addClass("card-flipped");
                            $(".cardOver .card"+e+"11").animate({right:"8.5vh"},400);
                            $(".cardOver .card"+e+"21").animate({right:"11.5vh"},400);
                            $(".cardOver .card"+e+"31").animate({right:"14.5vh"},400);
                        },250);
                    
                } else if(9==e||10==e||11==e||12==e){
                    $(".cardOver .card"+e+"11").animate({left:"8.5vh"},250);
                    $(".cardOver .card"+e+"21").animate({left:"8.5vh"},250);
                    $(".cardOver .card"+e+"31").animate({left:"8.5vh"},250);
                        setTimeout(function(){
                            $(".cardOver .cardtf"+e).addClass("card-flipped");
                            $(".cardOver .card"+e+"11").animate({left:"14.5vh"},400);
                            $(".cardOver .card"+e+"21").animate({left:"11.5vh"},400);
                            $(".cardOver .card"+e+"31").animate({left:"8.5vh"},400);
                        },250);
                    
                } else if(6==e){
                    $(".cardOver .card"+e+"11").animate({right:"6.5vh"},250);
                    $(".cardOver .card"+e+"21").animate({right:"6.5vh"},250);
                    $(".cardOver .card"+e+"31").animate({right:"6.5vh"},250);
                        setTimeout(function(){
                            $(".cardOver .cardtf"+e).addClass("card-flipped");
                            $(".cardOver .card"+e+"11").animate({right:"6.5vh"},400);
                            $(".cardOver .card"+e+"21").animate({right:"9.5vh"},400);
                            $(".cardOver .card"+e+"31").animate({right:"12.5vh"},400);
                        },250);
                    
                } else if(7==e){
                    $(".cardOver .card"+e+"11").animate({right:"42%"},250);
                    $(".cardOver .card"+e+"21").animate({right:"42%"},250);
                    $(".cardOver .card"+e+"31").animate({right:"42%"},250);
                        setTimeout(function(){
                            $(".cardOver .cardtf"+e).addClass("card-flipped");
                            $(".cardOver .card"+e+"11").animate({right:"42%"},400);
                            $(".cardOver .card"+e+"21").animate({right:"46%"},400);
                            $(".cardOver .card"+e+"31").animate({right:"50%"},400);
                        },250);
                } else if(8==e){
                    $(".cardOver .card"+e+"11").animate({left:"6.5vh"},250);
                    $(".cardOver .card"+e+"21").animate({left:"6.5vh"},250);
                    $(".cardOver .card"+e+"31").animate({left:"6.5vh"},250);
                        setTimeout(function(){
                            $(".cardOver .cardtf"+e).addClass("card-flipped");
                            $(".cardOver .card"+e+"11").animate({left:"12.5vh"},400);
                            $(".cardOver .card"+e+"21").animate({left:"9.5vh"},400);
                            $(".cardOver .card"+e+"31").animate({left:"6.5vh"},400);
                        },250);
                    
                } 
            },1);
        }
    },
    gameOverNew:function(e,t){
        appData.game.show_coin=!1;
        for(r=0;r<appData.playerBoard.score.length;r++){
            appData.playerBoard.score[r].num=0;
            appData.playerBoard.score[r].account_id=0;
            appData.playerBoard.score[r].nickname="";
            appData.playerBoard.score[r].account_code="";
            appData.playerBoard.score[r].account_score=0;
            appData.playerBoard.score[r].isBigWinner=0;
        }

        console.log(appData.playerBoard);
        for(r=0;r<12;r++)
            for(s in e)
                if(appData.player[r].account_id==s){
                    appData.player[r].account_score=Math.ceil(e[s]);
                    appData.playerBoard.score[r].num=appData.player[r].num;
                    appData.playerBoard.score[r].account_id=appData.player[r].account_id;
                    appData.playerBoard.score[r].nickname=appData.player[r].nickname;
                    appData.playerBoard.score[r].account_code=appData.player[r].account_code;
                    appData.playerBoard.score[r].account_score=appData.player[r].account_score;
                }

        var a=new Date,n="";
        n+=a.getFullYear()+"-";
        n+=a.getMonth()+1+"-";
        n+=a.getDate()+"  ";
        n+=a.getHours()+":";

        if(a.getMinutes()>=10){
            n+=a.getMinutes();
        } else {
            n+="0"+a.getMinutes();
        }
        appData.playerBoard.record=n;
        appData.base_score=appData.game.base_score;
        if(void 0!=t&&"-1"!=t){
            console.log(t);
            socketModule.processBalanceScoreboard(t);
        }

        for(var r=0;r<12;r++){
            appData.player[r].playing_status=0;
            appData.player[r].is_win=!1;
            appData.player[r].is_operation=!1;
            appData.player[r].win_type=0;
            appData.player[r].win_show=!1;
            appData.player[r].card=new Array;
            appData.player[r].card_open=new Array;
            appData.player[r].card_type=0;
            appData.player[r].is_showCard=!1;
            appData.player[r].is_readyPK=!1;
            appData.player[r].is_pk=!1;
            appData.player[r].multiples=0;
            appData.player[r].bankerMultiples=0;
            //appData.player[r].is_bull=!1;
            appData.player[r].is_showbull=!1;
            appData.player[r].is_audiobull=!1;
        }
        appData.game.can_open=0;
        appData.game.cardDeal=0;
        appData.game.status=1;
        appData.player[0].is_showCard=!1;
        appData.showClockRobText=!1;
        appData.showClockBetText=!1;
        appData.showClockShowCard=!1;
        appData.game.poolScore=0;
        $(".scoresArea").empty();
    },
    showMessage:function(){
        appData.isShowMessage=!0;
        disable_scroll();
        setTimeout(function(){
            if(appData.bScroll){
                appData.bScroll.refresh();
            } else {
                appData.bScroll=new BScroll(document.getElementById("message-box"),{
                    startX:0,
                    startY:0,
                    scrollY:!0,
                    scrollX:!1,
                    click:!0
                });
            }
        },10);
    },
    hideMessage:function(){appData.isShowMessage=!1,enable_scroll()},
    messageOn:function(e){
        socketModule.sendBroadcastVoice(e);
        m4aAudioPlay("message"+e);
        viewMethods.messageSay(0,e);
        viewMethods.hideMessage();
    },
    messageSay:function(e,t){
        appData.player[e].messageOn=!0;
        appData.player[e].messageText=appData.message[t].text;
        setTimeout(function(){
            appData.player[e].messageOn=!1;
        },2500);
    },
    closeEnd:function(){},
    roundEnd:function(){
        chooseBigWinner();
        $(".ranking .rankBack").css("opacity","1");
        $(".roundEndShow").show();
        setTimeout(function(){
            $(".ranking").show();
            canvas();
        },2500);
    },
    updateAllPlayerStatus:function(){
        for(var e=0;e<appData.player.length;e++){
            if(appData.player[e].multiples>0){
                appData.player[e].timesImg=globalData.fileUrl+"files/images/sangong/text_times"+appData.player[e].multiples+".png";
            }
            if(appData.player[e].bankerMultiples>0){
                appData.player[e].bankerTimesImg=globalData.fileUrl+"files/images/sangong/text_times"+appData.player[e].bankerMultiples+".png";
            }
            if(appData.player[e].card_type>=1){
                var t=20;
                var a=parseInt(appData.player[e].card_type);
                
                if(1==a){
                    t=20;
                }else if(4==a){
                    t=20;
                }else if(5==a){
                    t=11;
                }else if(6==a){
                    t='12_1';   //三条
                }else if(7==a){
                    t='12_1';   //三条
                }else if(8==a){
                    t=14;
                }else if(9==a){
                    t=15;
                }else if(10==a){
                    t=16;
                }else if(11==a){
                    t=17;
                }else {
                    t=appData.player[e].combo_point;
                }
                appData.player[e].bullImg=globalData.fileUrl+"files/images/sangong/point"+t+".png"
            }
            if(4==appData.player[e].account_status){
                if(5==appData.ruleInfo.banker_mode){
                    appData.player[e].robImg=globalData.fileUrl+"files/images/sangong/text_notgo.png";
                } else {
                    appData.player[e].robImg=globalData.fileUrl+"files/images/sangong/text_notrob.png";
                }
            } else if(5==appData.player[e].account_status){
                if(5==appData.ruleInfo.banker_mode){
                    appData.player[e].robImg=globalData.fileUrl+"files/images/sangong/text_go.png";
                } else {
                    appData.player[e].robImg=globalData.fileUrl+"files/images/sangong/text_rob.png";
                }
            } else if(6==appData.player[e].account_status){
                appData.player[e].multiples;
            } else if(7==appData.player[e].account_status){
                if(0==e){
                    viewMethods.seeMyCard();
                }
            } else if(8==appData.player[e].account_status){
                if(0==e){
                    viewMethods.myCardOver();
                } else {
                    viewMethods.cardOver(appData.player[e].num);
                }
            }
        }
    },
    timeCountDown:function(){
        if(1!=isTimeLimitShow){
            if(appData.game.time<=0){
                isTimeLimitShow=!1;
                return 0;
            } else {
                isTimeLimitShow=!0;
                appData.game.time--;
                timeLimit=setTimeout(function(){
                    isTimeLimitShow=!1;
                    viewMethods.timeCountDown();
                },1e3);
            }
        }
    },
    showRobBankerText:function(){
        appData.showTimesCoin=!1;
        appData.showRob=!1;
        appData.showShowCardButton=!1;
        appData.showClickShowCard=!1;
        appData.showNotRobText=!1;
        appData.showRobText=!0;
        appData.showBankerCoinText=!1
    },
    showNotRobBankerTextFnc:function(){
        appData.showTimesCoin=!1;
        appData.showRob=!1;
        appData.showShowCardButton=!1;
        appData.showClickShowCard=!1;
        appData.showNotRobText=!0;
        appData.showRobText=!1;
        appData.showBankerCoinText=!1
    },

    clickSelectTimesCoin:function(){
        appData.player[0].multiples=appData.raiseChip;
        viewMethods.throwCoin(1,parseInt(appData.raiseValue)+1);
        socketModule.sendPlayerMultiples(appData.raiseChip);
        appData.player[0].account_score=appData.player[0].account_score-appData.raiseChip;
        setTimeout(function(){mp3AudioPlay(appData.raiseChip)},50);
    },
    clickShowCard:function(){
        appData.showShowCardButton=!1;
        appData.showClickShowCard=!1;
        socketModule.sendShowCard();
    },

    showMemberScore:function(e){
        if(e){
            $(".memberScoreText1").show();
            $(".memberScoreText2").show();
            $(".memberScoreText3").show();
            $(".memberScoreText4").show();
            $(".memberScoreText5").show();
            $(".memberScoreText6").show();
            $(".memberScoreText7").show();
            $(".memberScoreText8").show();
            $(".memberScoreText9").show();
            $(".memberScoreText10").show();
            $(".memberScoreText11").show();
            $(".memberScoreText12").show();
        } else {
            $(".memberScoreText1").hide();
            $(".memberScoreText2").hide();
            $(".memberScoreText3").hide();
            $(".memberScoreText4").hide();
            $(".memberScoreText5").hide();
            $(".memberScoreText6").hide();
            $(".memberScoreText7").hide();
            $(".memberScoreText8").hide();
            $(".memberScoreText9").hide();
            $(".memberScoreText10").hide();
            $(".memberScoreText11").hide();
            $(".memberScoreText12").hide();
        }
    },
    winAnimate:function(obj){
        appData.isFinishWinAnimate=!1;
        var t=new Array;  //winner
        var a=new Array;  //loser
        appData.bankerPlayerNum=appData.bankerPlayer.num;

        for(n=0;n<obj.data.winner_array.length;n++)
            for(r=0;r<appData.player.length;r++)
                if(obj.data.winner_array[n].account_id==appData.player[r].account_id){
                        t.push(appData.player[r].num);
                }

        viewMethods.resetCoinsPosition();
        $("#playerCoins").show();
        for(n=1;n<=12;n++)
            viewMethods.showCoins(n,!1);

        //把金币暂时放到奖池位置
        for(n=0;n<t.length;n++)
            for(r=0;r<4;r++){
                $(".memberCoin"+t[n]+r).css("top","36%");
                $(".memberCoin"+t[n]+r).css("left","48%");
            }

        var o=100;
        var i=1800;
        
        setTimeout(function(){
            for(e=0;e<t.length;e++)
                viewMethods.showCoins(t[e],!0);
            for(e=0;e<t.length;e++)
                for(var n=0;n<4;n++)
                    $(".memberCoin"+t[e]+n).animate(memCoin[t[e]],150+150*n);
            setTimeout(function(){
                mp3AudioPlay("audioCoin")
            },10);
        },o);
        setTimeout(function(){
            viewMethods.finishWinAnimate(obj)
        },i);
    },
    finishWinAnimate:function(e){
        $("#playerCoins").hide();
        appData.game.show_card=!1;
        appData.game.show_score=!0;

        $(".memberScoreText1").fadeIn(200);
        $(".memberScoreText2").fadeIn(200);
        $(".memberScoreText3").fadeIn(200);
        $(".memberScoreText4").fadeIn(200);
        $(".memberScoreText5").fadeIn(200);
        $(".memberScoreText6").fadeIn(200);
        $(".memberScoreText7").fadeIn(200);
        $(".memberScoreText8").fadeIn(200);
        $(".memberScoreText9").fadeIn(200);
        $(".memberScoreText10").fadeIn(200);
        $(".memberScoreText11").fadeIn(200);
        $(".memberScoreText12").fadeIn(200,function(){
           
            viewMethods.gameOverNew(e.data.score_board,e.data.balance_scoreboard);

            setTimeout(function(){
                $(".memberScoreText1").fadeOut("slow");
                $(".memberScoreText2").fadeOut("slow");
                $(".memberScoreText3").fadeOut("slow");
                $(".memberScoreText4").fadeOut("slow");
                $(".memberScoreText5").fadeOut("slow");
                $(".memberScoreText6").fadeOut("slow");
                $(".memberScoreText7").fadeOut("slow");
                $(".memberScoreText8").fadeOut("slow");
                $(".memberScoreText9").fadeOut("slow");
                $(".memberScoreText10").fadeOut("slow");
                $(".memberScoreText11").fadeOut("slow");
                $(".memberScoreText12").fadeOut("slow");
               
                for(var e=0;e<12;e++){
                    appData.player[e].account_status>=3&&(appData.player[e].account_status=1)
                }
                
            },2e3);

            appData.isFinishWinAnimate=!0;
            if(e.data.total_num==e.data.game_num){
                setTimeout(function(){
                    viewMethods.roundEnd();
                    newNum=e.data.room_number;
                },1e3);
            }
        });
    },
    resetCoinsPosition:function(){
        for(var e=1;e<=12;e++)
            for(var t=0;t<4;t++)
                $(".memberCoin"+e+t).css(memCoin[e])
    },
    showCoins:function(e,t){
        if(t)
            for(a=0;a<4;a++)
                $(".memberCoin"+e+a).show();
        else 
            for(var a=0;a<4;a++)
                $(".memberCoin"+e+a).hide();
    },
    throwCoin:function(e,t){
        for(var a=1;a<=t;a++){
            appData.game.pollCoinNum=appData.game.pollCoinNum+1;
            var n=(.15*height-20)*Math.random();
            var r=(.28*width-20)*Math.random();
            if(height/width>1.8){
                n=(.1*height-20)*Math.random();
                r=(.2*width-20)*Math.random();
            }
            $(".scoresArea").append("<div class='coin coin"+e+" num"+appData.game.pollCoinNum+"' ></div>");
            $(".num"+appData.game.pollCoinNum).velocity({top:n,left:r},{duration:200+200*Math.random()})
        }
    }
};

var width=window.innerWidth;
var height=window.innerHeight;
var numD=0;
var isTimeLimitShow=!1;

var timesOffset=(.9*width-.088*height*4-.02*width*3)/2;
var coinLeft1=.045*height+"px";
var coinLeft2=width-.045*height+"px";
var coinLeft3=width-.045*height+"px";
var coinLeft4=width-.045*height+"px";
var coinLeft5=width-.06*height+"px";
var coinLeft6=.06*height+"px";
var coinLeft7=.045*height+"px";
var coinLeft8=.045*height+"px";
var coinLeft9=.045*height+"px";

// var memCoin = [
//     {},
//     {top: '82%', left: '4.5vh'},
//     {top: '59%', left: coinLeft2},
//     {top: '43%', left: coinLeft2},
//     {top: '27%', left: coinLeft2},
//     {top: '11%',  left: coinLeft5},
//     {top: '11%',  left: '15vh'},
//     {top: '27%', left: '4.5vh'},
//     {top: '43%', left: '4.5vh'},
//     {top: '59%', left: '4.5vh'},
//     ];

var memCoin = [
    {},
    {top: '82%', left: '5.0vw'},
    {top: '63%', left: '91.0vw'},
    {top: '51%', left: '91.0vw'},
    {top: '39%', left: '91.0vw'},
    {top: '27%', left: '91.0vw'},
    {top: '8%',  left: '88.0vw'},
    {top: '4%',  left: '48.5vw'},
    {top: '8%',  left: '8.0vw'},
    {top: '27%', left: '5.0vw'},
    {top: '39%', left: '5.0vw'},
    {top: '51%', left: '5.0vw'},
    {top: '63%', left: '5.0vw'}
    ];


var viewStyle={
    readyButton:{
        position:"absolute",
        top:(.11*height-.0495*height)/2+"px",
        left:(.9*width-.0495*height*3.078)/2+"px",
        width:.0495*height*3.078+"px",
        height:.0495*height+"px"
    },
    readyText:{
        position:"absolute",
        top:"50%",
        left:"50%",
        width:"6vh",
        height:"3vh",
        "margin-top":"-1.5vh",
        "margin-left":"-3vh"
    },
    button:{
        position:"absolute",
        top:"68%",
        left:"5%",
        width:"90%",
        height:"11vh",
        overflow:"hidden"
    },
    rob:{
        position:"absolute",
        top:(.11*height-.0495*height)/2+"px",
        left:(.9*width-.0495*height/.375*2-20)/2+"px",
        width:.0495*height/.375+"px",
        height:.0495*height+"px"
    },
    rob1:{
        position:"absolute",
        top:"0px",
        left:"0px",
        width:.0495*height/.375+"px",
        height:.0495*height+"px",
        "line-height":.0495*height+"px",
        "text-align":"center",
        color:"white",
        "font-size":"2.2vh",
        "font-weight":"bold"
    },
    notRob:{
        position:"absolute",
        top:(.11*height-.0495*height)/2+"px",
        left:(.9*width-.0495*height/.375*2-20)/2+.0495*height/.375+20+"px",
        width:.0495*height/.375+"px",
        height:.0495*height+"px"
    },
    notRob1:{
        position:"absolute",
        top:"0px",
        left:"0px",
        width:.0495*height/.375+"px",
        height:.0495*height+"px",
        "line-height":.0495*height+"px",
        "text-align":"center",
        color:"white",
        "font-size":"2.2vh",
        "font-weight":"bold"
    },
    showCard:{
        position:"absolute",
        top:(.11*height-.0495*height)/2+"px",
        left:(.9*width-.0495*height/.375)/2+"px",
        width:.0495*height/.375+"px",
        height:.0495*height+"px"
    },
    showCard1:{
        position:"absolute",
        top:"0px",
        left:"0px",
        width:.0495*height/.375+"px",
        height:.0495*height+"px",
        "line-height":.0495*height+"px",
        "text-align":"center",
        color:"white",
        "font-size":"2.2vh",
        "font-weight":"bold"
    },
        times1:{position:"absolute",
        top:(.11*height-.088*height/2)/2+"px",
        left:timesOffset+"px",
        width:.088*height+"px",
        height:.088*height/2+"px",
        "line-height":.088*height/2+"px"
    },
    timesText:{
        position:"absolute",
        width:.088*height+"px",
        height:.088*height/2+"px",
        "line-height":.088*height/2+"px",
        "text-align":"center",
        color:"white",
        "font-size":"2.2vh",
        "font-weight":"bold"
    },
    times2:{
        position:"absolute",
        top:(.11*height-.088*height/2)/2+"px",
        left:timesOffset+.02*width+.088*height+"px",
        width:.088*height+"px",
        height:.088*height/2+"px",
        "line-height":.088*height/2+"px"
    },
    times3:{position:"absolute",
        top:(.11*height-.088*height/2)/2+"px",
        left:timesOffset+.02*width*2+.088*height*2+"px",
        width:.088*height+"px",
        height:.088*height/2+"px",
        "line-height":.088*height/2+"px"
    },
    times4:{
        position:"absolute",
        top:(.11*height-.088*height/2)/2+"px",
        left:timesOffset+.02*width*3+.088*height*3+"px",
        width:.088*height+"px",
        height:.088*height/2+"px",
        "line-height":.088*height/2+"px"
    },
    robText2:{
        position:"absolute",
        top:(.11*height-.03*height)/2+"px",
        left:(.9*width-.0557*height-.03*height-.005*height)/2+"px",
        width:.0557*height+"px",
        height:.03*height+"px"
    },
    robText:{
        position:"absolute",
        top:(.11*height-.03*height)/2+"px",
        left:(.9*width-.0557*height)/2+"px",
        width:.0557*height+"px",
        height:.03*height+"px"
    },
    robTimesText:{
        position:"absolute",
        top:(.11*height-.03*height)/2+"px",
        left:(.9*width-.0557*height-.03*height-.002*height)/2+.0557*height+.005*height+"px",
        width:.03*height+"px",
        height:.03*height+"px"},
        notRobText:{position:"absolute",
        top:(.11*height-.03*height)/2+"px",
        left:(.9*width-.0557*height)/2+"px",
        width:.0557*height+"px",
        height:.03*height+"px"
    },
    showCardText:{
        position:"absolute",
        top:"10%",
        left:"10%",
        width:"80%",
        height:"11vh",
        "font-size":"2.2vh"
    },
    showCardText1:{
        position:"absolute",
        width:"100%",
        height:"100%",
        color:"white",
        "font-size":"2.2vh",
        "text-align":"center",
        "line-height":"11vh",
        "font-family":"Helvetica 微软雅黑"
    },
    coinText:{
        position:"absolute",
        top:"10%",
        left:"10%",
        width:"80%",
        height:"11vh",
        "font-size":"2.2vh"
    },
    coinText1:{
        position:"absolute",
        width:"100%",
        height:"100%",
        color:"white",
        "font-size":"2.2vh",
        "text-align":"center",
        "line-height":"11vh",
        "font-family":"Helvetica 微软雅黑"
    }
};
var ruleInfo={
    type:-1,
    isShow:!1,
    isShowRule:!1,
    baseScore:1,
    timesType:1,
    is_cardjoker: 0,
    is_cardbao9: 0,
    ticket:1,
    rule_height:"4vh",
    banker_mode:1,
    banker_score:1,
    bankerText:"抢庄"
};
var editAudioInfo={
    isShow:!1,
    backMusic:1,
    messageMusic:1
};
var audioInfo={
    backMusic:1,
    messageMusic:1
};

if(localStorage.backMusic){
    editAudioInfo.backMusic=localStorage.backMusic;
    audioInfo.backMusic=localStorage.backMusic;
} else {
    localStorage.backMusic=1;
}
if(localStorage.messageMusic){
    editAudioInfo.messageMusic=localStorage.messageMusic;
    audioInfo.messageMusic=localStorage.messageMusic;
} else {
    localStorage.messageMusic=1;
}

var appData={
    is_X:!1,
    isGetDogRP:0,
    isShowDogRP:0,
    canGetDogRP:1,
    dogRPText:"",
    numAry:[0,1,2,3,4,5,6,7,8,9],
    minRaise:0,
    maxRaise:9,
    raiseValue:0,
    raiseStep:1,
    raiseChip:30,
    user_id:userData.accountId,
    viewStyle:viewStyle,
    roomStatus:globalData.roomStatus,
    isAA:!1,isAutoActive:!1,
    width:window.innerWidth,
    height:window.innerHeight,
    roomCard:Math.ceil(globalData.card),
    is_connect:!1,
    player:[],
    scoreboard:"",
    activity:[],
    isShowInvite:!1,
    isShowAlert:!1,
    isShowShop:!1,
    isShowMessage:!1,
    alertType:0,
    alertText:"",
    showRob:!1,
    showShowCardButton:!1,
    showRobText:!1,
    showNotRobText:!1,
    showClockRobText:!1,
    showClockBetText:!1,
    showClockShowCard:!1,
    showTimesCoin:!1,
    showClickShowCard:!1,
    showBankerCoinText:!1,
    clickCard3:!1,
    base_score:0,
    playerBoard:{
        score:new Array,
        round:0,
        record:""
    },
    game:game,
    roomCardInfo:[],
    wsocket:ws,
    connectOrNot:!0,
    socketStatus:0,
    heartbeat:null,
    select:1,
    ticket_count:0,
    isDealing:!1,
    message:message,
    isShowShopLoading:!1,
    bankerArray:[],
    bankerAccountId:"",
    bankerPlayer:"",
    bankerPlayerNum:-1,
    bankerAnimateCount:0,
    bankerAnimateIndex:0,
    lastBankerImgId:"",
    bankerAnimateDuration:120,
    isFinishWinAnimate:!1,
    isFinishBankerAnimate:!1,
    isShowErweima:!1,
    isShowRecord:!1,
    recordList:[],
    ruleInfo:ruleInfo,
    canBreak:0,
    overType:1,
    isBreak:0,
    breakData:"",
    bankerID:0,
    editAudioInfo:editAudioInfo,
    audioInfo:audioInfo,
    isReconnect:!0,
    bScroll:null,
    isShowNoteImg:!1,

    //广播
    isShowNoty : false,
    notyMsg   : ''
};

//广播
setTimeout(function () {
    if (globalData.isNotyMsg != undefined && globalData.isNotyMsg != null) {
        appData.notyMsg = globalData.notyMsg;
        if (globalData.isNotyMsg == 1) {
            appData.isShowNoty = true;
            setTimeout(function () {
                appData.isShowNoty = false;
            }, globalData.notyTime * 1000);
        }
    } else {
        globalData.isNotyMsg = 0;
    }

    $('#marquee').marquee({
        //speed in milliseconds of the marquee
        duration: globalData.notySpeed,
        //gap in pixels between the tickers
        gap: 400,
        //time in milliseconds before the marquee will start animating
        delayBeforeStart: 0,
        //'left' or 'right'
        direction: 'left',
        //true or false - should the marquee be duplicated to show an effect of continues flow
        duplicated: true
    });

}, 50);
//end 广播

var resetState=function(){
    appData.game.show_score=!1;
    appData.game.show_bettext=!1;
    appData.clickCard3=!1;
    for(e=0;e<12;e++) {
        appData.player.push({
            num:e+1,
            serial_num:e+1,
            account_id:0,
            account_status:0,
            playing_status:0,
            online_status:0,
            nickname:"",
            account_code:"",
            headimgurl:"",
            account_score:0,
            ticket_checked:1,
            is_win:!1,
            win_type:0,
            limit_time:0,
            is_operation:!1,
            win_show:!1,
            card:[],
            card_open:[],
            is_showCard:!1,
            is_pk:!1,
            is_readyPK:!1,
            card_type:0,
            is_banker:!1,
            multiples:0,
            bankerMultiples:0,
            combo_point:0,
            timesImg:"",
            bankerTimesImg:"",
            robImg:"",
            bullImg:"",
            single_score:0,
            messageOn:!1,
            is_showbull:!1,
            is_audiobull:!1,
            is_showCard:!1,
            messageText:"",
            coins:[]
        });
        appData.playerBoard.score.push({
            account_id:0,
            nickname:"",
            account_code:"",
            account_score:0,
            isBigWinner:0
        });
    }
    for(var e=0;e<appData.player.length;e++){
        appData.player[e].coins=[];
        for(var t=0;t<4;t++)
            appData.player[e].coins.push("memberCoin"+appData.player[e].num+t);
    }
    httpModule.getManageInfo();
};
var resetAllPlayerData=function(){
    appData.player=[];
    for(e=0;e<12;e++)
        appData.player.push({
            num:e+1,
            serial_num:e+1,
            account_id:0,
            account_status:0,
            playing_status:0,
            online_status:0,
            nickname:"",
            account_code:"",
            headimgurl:"",
            account_score:0,
            ticket_checked:0,
            is_win:!1,
            win_type:0,
            limit_time:0,
            is_operation:!1,
            win_show:!1,
            card:new Array,
            card_open:new Array,
            is_showCard:!1,
            is_pk:!1,
            is_readyPK:!1,
            card_type:0,
            is_banker:!1,
            multiples:0,
            bankerMultiples:0,
            combo_point:0,
            timesImg:"",
            bankerTimesImg:"",
            robImg:"",
            bullImg:"",
            single_score:0,
            messageOn:!1,
            is_showbull:!1,
            is_audiobull:!1,
            messageText:"",
            coins:[]
        });
    for(var e=0;e<appData.player.length;e++){
        appData.player[e].coins=[];
        for(var t=0;t<4;t++)
            appData.player[e].coins.push("memberCoin"+appData.player[e].num+t)
    }
};
var newGame=function(){
    appData.playerBoard={
        score:new Array,
        round:0,
        record:""
    };
    appData.game.round=0;
    appData.game.status=1;
    appData.game.cardDeal=0;
    appData.game.can_open=0;
    appData.game.current_win=0;
    appData.game.is_play=!1;
    appData.game.show_score=!1;
    appData.game.show_bettext=!1;
    appData.clickCard3=!1;
  
    for(var e=0;e<appData.player.length;e++) {
        appData.playerBoard.score.push({
            account_id:0,
            nickname:"",
            account_code:"",
            account_score:0,
            isBigWinner:0
        });
        if(1==appData.player[e].online_status){
            appData.player[e].account_status=0;
            appData.player[e].playing_status=0;
            appData.player[e].is_win=!1;
            appData.player[e].is_operation=!1;
            appData.player[e].win_type=0;
            appData.player[e].win_show=!1;
            appData.player[e].card=new Array;
            appData.player[e].card_open=new Array;
            appData.player[e].card_type=0;
            appData.player[e].ticket_checked=0;
            appData.player[e].account_score=0;
            appData.player[e].is_showCard=!1;
            appData.player[e].is_readyPK=!1;
            appData.player[e].is_pk=!1;
            appData.player[e].is_banker=!1;
            appData.player[e].multiples=0;
            appData.player[e].bankerMultiples=0;
            appData.player[e].combo_point=0;
            appData.player[e].timesImg="";
            appData.player[e].bankerTimesImg="";
            appData.player[e].robImg="";
            appData.player[e].bullImg="";
            appData.player[e].single_score=0;
            appData.player[e].num=e+1;
            //appData.player[e].is_bull=!1;
            appData.player[e].is_showbull=!1;
            appData.player[e].is_audiobull=!1;
        } else {
            appData.player[e]={
                num:e+1,
                serial_num:appData.player[e].serial_num,
                account_id:0,
                account_status:0,
                playing_status:0,
                online_status:0,
                nickname:"",
                account_code:"",
                headimgurl:"",
                account_score:0,
                is_win:!1,
                win_type:0,
                ticket_checked:0,
                limit_time:0,
                is_operation:!1,
                win_show:!1,
                card:new Array,
                card_open:new Array,
                is_showCard:!1,
                is_pk:!1,
                is_readyPK:!1,
                card_type:0,
                is_banker:!1,
                multiples:0,
                bankerMultiples:0,
                combo_point:0,
                timesImg:"",
                bankerTimesImg:"",
                robImg:"",
                bullImg:"",
                single_score:0,
                //is_bull:!1,
                is_showbull:!1,
                is_audiobull:!1
            };
        }
    }
};
var connectSocket=function(e,t,a,n,r){
    ws=new WebSocket(e)
    ws.onopen=t;ws.onmessage=a;
    ws.onclose=n;
    ws.onerror=r;
};
var wsOpenCallback=function(e){
    logMessage("websocket is opened");
    appData.connectOrNot=!0;
    if(appData.heartbeat){
        clearInterval(appData.heartbeat);
    }
    appData.heartbeat=setInterval(function(){
        appData.socketStatus=appData.socketStatus+1;
        if(appData.socketStatus>1){
            appData.connectOrNot=!1;
        }
        if(appData.socketStatus>4&&appData.isReconnect){
            methods.reloadView();
        }
        if(ws.readyState==WebSocket.OPEN){
            ws.send("@");
        }
    },3e3);
    socketModule.sendPrepareJoinRoom();
};
var wsMessageCallback=function wsMessageCallback(evt){
    appData.connectOrNot=!0;
    if("@"==evt.data){
        appData.socketStatus=0;
        return 0;
    }
    var obj=eval("("+evt.data+")");

    if(-201==obj.result){
        viewMethods.clickShowAlert(31,obj.result_message);
    } else if(-202==obj.result){
        appData.isReconnect=!1;
        socketModule.closeSocket();
        viewMethods.clickShowAlert(32,obj.result_message);
    } else if(-203==obj.result){
        methods.reloadView();
    }

    if(0!=obj.result){
        if(obj.operation==wsOperation.JoinRoom){
            if(1==obj.result){
                if(1==obj.data.alert_type){
                    viewMethods.clickShowAlert(1,obj.result_message);
                } else if(2==obj.data.alert_type){
                    viewMethods.clickShowAlert(2,obj.result_message);
                } else if(3==obj.data.alert_type){
                    viewMethods.clickShowAlert(11,obj.result_message);
                } else {
                    viewMethods.clickShowAlert(7,obj.result_message);
                }
            } else {
                obj.result,viewMethods.clickShowAlert(7,obj.result_message);
            }
        } else if(obj.operation==wsOperation.ReadyStart){
            if(1==obj.result){
                viewMethods.clickShowAlert(1,obj.result_message);
            }
        } else if(obj.operation==wsOperation.PrepareJoinRoom){
            if(obj.result>0){
                socketModule.processGameRule(obj);
            }
            if(1==obj.result){
                if(1==obj.data.alert_type){
                    viewMethods.clickShowAlert(1,obj.result_message);
                } else if(2==obj.data.alert_type){
                    viewMethods.clickShowAlert(2,obj.result_message);
                } else if(3==obj.data.alert_type){
                    viewMethods.clickShowAlert(11,obj.result_message);
                } else {
                    viewMethods.clickShowAlert(7,obj.result_message);
                }
            } else {
                obj.result,viewMethods.clickShowAlert(7,obj.result_message);
            }
        } else if(obj.operation==wsOperation.RefreshRoom){
            methods.reloadView();
        }
        appData.player[0].is_operation=!1;
    } else {
        switch(obj.operation){
            case wsOperation.PrepareJoinRoom:
                socketModule.processPrepareJoinRoom(obj);
                break;
            case wsOperation.JoinRoom:
                socketModule.processJoinRoom(obj);
                break;
            case wsOperation.RefreshRoom:
                socketModule.processRefreshRoom(obj);
                break;
            case wsOperation.AllGamerInfo:
                socketModule.processAllGamerInfo(obj);
                break;
            case wsOperation.UpdateGamerInfo:
                socketModule.processUpdateGamerInfo(obj);
                break;
            case wsOperation.UpdateAccountStatus:
                socketModule.processUpdateAccountStatus(obj);
                break;
            case wsOperation.UpdateAccountShow:
                socketModule.processUpdateAccountShow(obj);
                break;
            case wsOperation.UpdateAccountMultiples:
                socketModule.processUpdateAccountMultiples(obj);
                break;
            case wsOperation.StartLimitTime:
                socketModule.processStartLimitTime(obj);
                break;
            case wsOperation.CancelStartLimitTime:
                socketModule.processCancelStartLimitTime(obj);
                break;
            case wsOperation.GameStart:
                socketModule.processGameStart(obj);
                break;
          
            case wsOperation.UpdateAccountScore:
                socketModule.processUpdateAccountScore(obj);
                break;
            case wsOperation.Win:
                socketModule.processWin(obj);
                break;
            case wsOperation.BroadcastVoice:
                socketModule.processBroadcastVoice(obj);
                break;
            case wsOperation.StartBet:
                socketModule.processStartBet(obj);
                break;
            case wsOperation.StartShow:
                socketModule.processStartShow(obj);
                break;
            case wsOperation.MyCards:
                socketModule.processMyCards(obj);
                break;
            default:
                logMessage(obj.operation);
        }
    }
};
var wsCloseCallback=function(e){
    logMessage("websocket closed：");
    logMessage(e);
    appData.connectOrNot=!1;
    reconnectSocket();
};
var wsErrorCallback=function(e){
    logMessage("websocket onerror：");
    logMessage(e);
};
var reconnectSocket=function(){
    if(appData.isReconnect&&4!=globalData.roomStatus){
        if(ws){
            if(logMessage(ws.readyState),1==ws.readyState)return;
            ws=null
        }
        logMessage("reconnectSocket"),
        connectSocket(globalData.socket,wsOpenCallback,wsMessageCallback,wsCloseCallback,wsErrorCallback)
    }
};
var m4aAudioPlay=function(e){
    if(!audioModule.audioOn)return 0;
    audioModule.playSound(e)
};
var mp3AudioPlay=function(e){
    if(!audioModule.audioOn)return 0;
    audioModule.playSound(e)
};
var audioModule={
    audioOn:!1,
    audioContext:null,
    audioBuffers:[],
    baseUrl:"",
    initModule:function(e){
        this.baseUrl=e;
        this.audioBuffers=[];
        window.AudioContext=window.AudioContext||window.webkitAudioContext||window.mozAudioContext||window.msAudioContext;
        this.audioContext=new window.AudioContext
    },
    stopSound:function(e){
        var t=this.audioBuffers[e];
        t&&t.source&&(t.source.stop(0),t.source=null)
    },
    playSound:function(e,t){
        if("backMusic"==e){
            if(0==audioInfo.backMusic)return
        } else if(0==audioInfo.messageMusic)return;

        var a=this.audioBuffers[e];
        if(a){
            try{
                if(void 0!=WeixinJSBridge){
                    WeixinJSBridge.invoke("getNetworkType",{},function(e){
                        a.source=null;
                        a.source=audioModule.audioContext.createBufferSource();
                        a.source.buffer=a.buffer;
                        a.source.loop=!1;
                        var n=audioModule.audioContext.createGain();
                        if(1==t){
                            a.source.loop=!0;
                            n.gain.value=.7;
                        } else {
                            n.gain.value=1;
                        }
                        a.source.connect(n);
                        n.connect(audioModule.audioContext.destination);
                        a.source.start(0);
                    });
                }
            }catch(e){}
        }
    },
    initSound:function(e,t){
        this.audioContext.decodeAudioData(e,function(e){
            audioModule.audioBuffers[t]={name:t,buffer:e,source:null};
            if("backMusic"==t){
                audioModule.audioOn=!0;
                audioModule.playSound(t,!0);
            }
        },function(e){
            logMessage("Error decoding file",e);
        });
    },
    loadAudioFile:function(e,t){
        var a=new XMLHttpRequest;
        a.open("GET",e,!0);
        a.responseType="arraybuffer";
        a.onload=function(e){
            audioModule.initSound(a.response,t);
        };
        a.send();
    },
    loadAllAudioFile:function(){
        if(4!=globalData.roomStatus&&1!=isLoadAudioFile){
            isLoadAudioFile=!0;
            this.loadAudioFile(this.baseUrl+"files/audio/sangong/background8.mp3","backMusic");
            var e=["0.m4a","1.m4a","2.m4a","3.m4a","4.m4a","5.m4a","6.m4a","7.m4a","8.m4a","9.m4a",
            "special5.m4a","special_santiao.m4a","special_santiao.m4a","special8.m4a","special9.m4a","special10.m4a","special11.m4a",
            "coin.mp3","audio1.m4a"];
            var t=["sangong0","sangong1","sangong2","sangong3","sangong4","sangong5","sangong6","sangong7","sangong8","sangong9",
            "special5", "special6", "special7", "special8", "special9", "special10", "special11",
            "audioCoin","audio1"];
            for(a=0;a<e.length;a++)
                this.loadAudioFile(this.baseUrl+"files/audio/sangong/"+e[a],t[a]);

            var filename = ["30.m4a","50.m4a","60.m4a","90.m4a","100.m4a","120.m4a","150.m4a","180.m4a",
            "200.m4a","210.m4a","240.m4a","250.m4a","270.m4a","300.m4a","350.m4a","400.m4a","450.m4a",
            "500.m4a","600.m4a","700.m4a","800.m4a","900.m4a","1000.m4a"];
            var refername = ["30","50","60","90","100","120","150","180",
            "200","210","240","250","270","300","350","400","450",
            "500","600","700","800","900","1000"];
            for(a=0;a<filename.length;a++)
                this.loadAudioFile(this.baseUrl+"files/audio/dcx/"+filename[a],refername[a]);

            var n=["message9.m4a","message10.m4a","message11.m4a","message1.m4a","message2.m4a","message3.m4a","message4.m4a","message12.m4a",
            "message6.m4a","message7.m4a","message8.m4a"];
            var r=["message0","message1","message2","message3","message4","message5","message6","message7",
            "message8","message9","message10"];
            for(a=0;a<n.length;a++)
                this.loadAudioFile(this.baseUrl+"files/audio/sound/"+n[a],r[a])
        }
    }
};
audioModule.initModule(globalData.fileUrl);

var initView=function(){
    $("#app-main").width(appData.width);
    $("#app-main").height(appData.height);
    $("#table").width(appData.width);
    $("#table").height(appData.height);
    $(".ranking").css("width",2*appData.width);
    $(".ranking").css("height",2*appData.width*1.621);

    window.onload=function(){
        var e=["table","vinvite","valert","vmessage","vcreateRoom","vroomRule","endCreateRoom","endCreateRoomBtn"];
        for(t=e.length,a=0;a<t;a++){
            var n=document.getElementById(e[a]);
            if(n){
                n.addEventListener("touchmove",function(e){
                    e.preventDefault()
                },!1);
            }
        }
    };
};
var methods={
    raiseValueChange:function(){
        appData.raiseChip=appData.game.chips[appData.raiseValue]
    },
    showAlert:viewMethods.clickShowAlert,
    showMessage:viewMethods.showMessage,
    closeAlert:viewMethods.clickCloseAlert,
    sitDown:viewMethods.clickSitDown,
    seeMyCard3:viewMethods.seeMyCard3,
    imReady:viewMethods.clickReady,
    imCloseRoom:viewMethods.clickCloseRoom,
    showCard:viewMethods.clickShowCard,
    selectTimesCoin:viewMethods.clickSelectTimesCoin,
    hideMessage:viewMethods.hideMessage,
    closeEnd:viewMethods.closeEnd,
    messageOn:viewMethods.messageOn,
    hall:function(){
        window.location.href = globalData.hallPath;
    },
    showGameRule:function(){
        if(4!=appData.roomStatus){
            $(".createRoom .mainPart").css("height","60vh");
            $(".createRoom .mainPart .blueBack").css("height","51vh");
            appData.ruleInfo.isShowRule=!0;
        }
    },
    cancelGameRule:function(){
        appData.ruleInfo.isShowRule=!1;
        $(".createRoom .mainPart").css("height","65vh");
        $(".createRoom .mainPart .blueBack").css("height","46vh");
    },
    showBreakRoom:function(){
        if(null!=appData.breakData&&void 0!=appData.breakData){
            viewMethods.gameOverNew(appData.breakData.data.score_board,appData.breakData.data.balance_scoreboard);
        }
        chooseBigWinner();
        $(".ranking .rankBack").css("opacity","1");
        $(".roundEndShow").show();
        $(".ranking").show();
        canvas();
    },
    showAudioSetting:function(){
        appData.editAudioInfo.backMusic=appData.audioInfo.backMusic;
        appData.editAudioInfo.messageMusic=appData.audioInfo.messageMusic;
        appData.editAudioInfo.isShow=!0;
    },
    cancelAudioSetting:function(){appData.editAudioInfo.isShow=!1},
    confirmAudioSetting:function(){
        appData.editAudioInfo.isShow=!1;
        appData.audioInfo.backMusic=appData.editAudioInfo.backMusic;
        appData.audioInfo.messageMusic=appData.editAudioInfo.messageMusic;
        localStorage.backMusic=appData.editAudioInfo.backMusic;
        localStorage.messageMusic=appData.editAudioInfo.messageMusic;
        if(1==appData.audioInfo.backMusic){
            audioModule.stopSound("backMusic");
            audioModule.playSound("backMusic",!0);
        } else {
            audioModule.stopSound("backMusic");
        }
    },
    setBackMusic:function(){
        if(0==appData.editAudioInfo.backMusic){
            appData.editAudioInfo.backMusic=1;
        } else {
            appData.editAudioInfo.backMusic=0;
        }
    },
    setMessageMusic:function(){
        if(0==appData.editAudioInfo.messageMusic){
            appData.editAudioInfo.messageMusic=1;
        } else {
            appData.editAudioInfo.messageMusic=0;
        }
    },
    reloadView:function(){
        window.location.href = window.location.href + "&id=" + 1000 * Math.random();
    },
    showNoteImg:function(){appData.isShowNoteImg=!0},
    hideNoteImg:function(){appData.isShowNoteImg=!1},
};
var vueLife={
    vmCreated:function(){
        logMessage("vmCreated");
        resetState();
        initView();
        if(4!=globalData.roomStatus){
            $("#loading").hide();
        }
        $(".main").show();
    },
    vmUpdated:function(){logMessage("vmUpdated")},
    vmMounted:function(){
        logMessage("vmMounted");
        $("#marquee").marquee({
            duration:globalData.notySpeed,
            gap:50,delayBeforeStart:0,
            direction:"left",
            duplicated:!0
        });
    },
    vmDestroyed:function(){logMessage("vmDestroyed")}
};

var vm=new Vue({
    el:"#app-main",
    data:appData,
    methods:methods,
    created:vueLife.vmCreated,
    updated:vueLife.vmUpdated,
    mounted:vueLife.vmMounted,
    destroyed:vueLife.vmDestroyed
});

function preventDefaultFn(e){
    e.preventDefault();
}
function disable_scroll(){
    $("body").on("touchmove",preventDefaultFn);
}
function enable_scroll(){
    $("body").off("touchmove",preventDefaultFn);
}

var shareContent="";
function getShareContent(){
    shareContent="\n";
    if(1==appData.ruleInfo.bet_type){
        shareContent+="筹码：300 ";
    } else if(2==appData.ruleInfo.bet_type){
        shareContent+="筹码：500 ";
    } else if(3==appData.ruleInfo.bet_type){
        shareContent+="筹码：1000 ";
    }
    if(1==appData.ruleInfo.is_cardjoker||1==appData.ruleInfo.is_cardbao9){
        var e="  牌型：";
        if(1==appData.ruleInfo.is_cardjoker){
            e+=" 天公,雷公,地公 ";
        }
        if(1==appData.ruleInfo.is_cardbao9){
            e+=" 暴玖 ";
        }
      
        shareContent+=e;
    }
    if(1==appData.ruleInfo.ticket){
        shareContent+="  局数：12局x3张房卡";
    } else {
        shareContent+="  局数：24局x6张房卡";
    }
}

var wxModule={
    config:function(){
        wx.config({
            debug:!1,
            appId:configData.appId,
            timestamp:configData.timestamp,
            nonceStr:configData.nonceStr,
            signature:configData.signature,
            jsApiList:["onMenuShareTimeline","onMenuShareAppMessage","hideMenuItems"]
        });
        getShareContent();
        wx.onMenuShareTimeline({
            title:globalData.shareTitle,
            desc:shareContent,
            link:globalData.roomUrl,
            imgUrl:globalData.fileUrl+"files/images/dcx/share_dcx.png",
            success:function(){},
            cancel:function(){}
        });
        wx.onMenuShareAppMessage({
            title:globalData.shareTitle,
            desc:shareContent,
            link:globalData.roomUrl,
            imgUrl:globalData.fileUrl+"files/images/dcx/share_dcx.png",
            success:function(){},
            cancel:function(){}
        })
    }
};
wx.config({
    debug:!1,
    appId:configData.appId,
    timestamp:configData.timestamp,
    nonceStr:configData.nonceStr,
    signature:configData.signature,
    jsApiList:["onMenuShareTimeline","onMenuShareAppMessage","hideMenuItems"]
});
var isLoadAudioFile=!1;
wx.ready(function(){
    audioModule.loadAllAudioFile();
    wx.hideMenuItems({
        menuList:["menuItem:copyUrl","menuItem:share:qq","menuItem:share:weiboApp",
        "menuItem:favorite","menuItem:share:facebook","menuItem:share:QZone","menuItem:refresh"]
    });
    getShareContent();
    wx.onMenuShareTimeline({
        title:globalData.shareTitle,
        desc:shareContent,
        link:globalData.roomUrl,
        imgUrl:globalData.fileUrl+"files/images/dcx/share_dcx.png",
        success:function(){},
        cancel:function(){}
    });
    wx.onMenuShareAppMessage({
        title:globalData.shareTitle,
        desc:shareContent,
        link:globalData.roomUrl,
        imgUrl:globalData.fileUrl+"files/images/dcx/share_dcx.png",
        success:function(){},
        cancel:function(){}
    })
});
wx.error(function(e){});

if(4==globalData.roomStatus){
    setTimeout(function(){
        try{
            var obj=eval("("+globalData.scoreboard+")");
            setTimeout(function(){
                socketModule.processLastScoreboard(obj)
            },0)
        }catch(e){
            console.log(e),
            setTimeout(function(){
                socketModule.processLastScoreboard("")
            },0)
        }
    },50);
}

function canvas(){
    var e=document.getElementById("ranking");
    html2canvas(e,{
        allowTaint:!0,
        taintTest:!1,
        onrendered:function(e){
            e.id="mycanvas";
            var t=e.toDataURL("image/jpeg",.5);
            $("#end").attr("src",t);
            $(".end").show();
            $(".ranking").hide();
            newGame()
        }
    });
}

function logMessage(e){console.log(e)}

function chooseBigWinner(){

    //对积分榜排序
    appData.playerBoard.score.sort(function(a,b){
        return b.account_score - a.account_score;
    });   

    var e=appData.playerBoard.score.length;
    t=1;
    for(a=0;a<e;a++){
        appData.playerBoard.score.isBigWinner=0;
        if(appData.playerBoard.score[a].account_score>t){
            t=appData.playerBoard.score[a].account_score;
        }
    }
    for(var n=0;n<e;n++){
        if(appData.playerBoard.score[n].account_score==t){
            appData.playerBoard.score[n].isBigWinner=1;
        }
    }
}

function getComboCards(e){
    try{
        if(void 0==e||3!=e.length)
            return e;
        var t=!1;
        var a=new Array;
        var n=new Array;
        for(r=0;r<e.length;r++){
            var o=e[r];
            if("-1"==o||-1==o||""==o)
                return e;
            o=o.substr(1);
            a.push(parseInt(o))
        }
        for(r=0;r<e.length-2;r++){
            for(var i=r+1;i<e.length-1;i++){
                for(var s=i+1;s<e.length-0;s++)
                    if(((a[r]>10?10:a[r])+(a[i]>10?10:a[i])+(a[s]>10?10:a[s]))%10==0){
                        n.push(e[r]),n.push(e[i]),n.push(e[s]);
                        for(var c=0;c<e.length;c++)
                            e[c]!=e[r]&&e[c]!=e[i]&&e[c]!=e[s]&&n.push(e[c]);
                        t=!0
                    }
                if(t)break
            }
            if(t)break
        }
        if(n.length<1)
            n=e;
        return n
    }catch(t){
        return e
    }
}


$(function(){
    if(height/width>1.8){
        $(".scoresArea").css("width","20%");
        $(".scoresArea").css("height","10vh");
        $(".scoresArea").css("left","40%");
        appData.is_X=!0;
    }
    sessionStorage.isPaused="false";
    var e,t;
    if(void 0!==document.hidden){
        e="hidden";
        t="visibilitychange";
    } else if(void 0!==document.webkitHidden){
        e="webkitHidden";
        t="webkitvisibilitychange";
    }

    if(void 0===document.addEventListener||void 0===e){
        alert("This demo requires a browser such as Google Chrome that supports the Page Visibility API.");
    } else {
        document.addEventListener(t,function(){
            if(document[e]){
                audioModule.audioOn=!1;
                audioModule.stopSound("backMusic");
            } else if("true"!==sessionStorage.isPaused){
                console.log("play backMusic");
                audioModule.audioOn=!0;
                audioModule.stopSound("backMusic");
                audioModule.playSound("backMusic",!0);
            }
        }, !1);
    }
   
    $.fn.RangeSlider=function(e){
        this.sliderCfg={
            min:e&&!isNaN(parseFloat(e.min))?Number(e.min):null,
            max:e&&!isNaN(parseFloat(e.max))?Number(e.max):null,
            step:e&&Number(e.step)?e.step:1,
            callback:e&&e.callback?e.callback:null
        };
        var t=$(this);
        var a=this.sliderCfg.min;
        var n=this.sliderCfg.max;
        var r=this.sliderCfg.step;
        var o=this.sliderCfg.callback;
        t.attr("min",a).attr("max",n).attr("step",r);
        t.bind("input",function(e){
            t.attr("value",this.value);
            $.isFunction(o)&&o(this)
        })
    };
    $("input").RangeSlider({min:0,max:9,step:0,callback:function(e){console.log(appData.raiseValue)}})
});